-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution.c
45 lines (36 loc) · 904 Bytes
/
Solution.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
void sortString(char* str) {
int i, j;
char temp;
int len = strlen(str);
for (i = 0; i < len - 1; i++) {
for (j = i + 1; j < len; j++) {
if (str[i] > str[j]) {
temp = str[i];
str[i] = str[j];
str[j] = temp;
}
}
}
}
bool areAnagrams(char* str1, char* str2) {
if (strlen(str1) != strlen(str2))
return false;
sortString(str1);
sortString(str2);
return strcmp(str1, str2) == 0;
}
int main() {
char str1[100], str2[100];
printf("Enter the first string: ");
scanf("%s", str1);
printf("Enter the second string: ");
scanf("%s", str2);
if (areAnagrams(str1, str2))
printf("The strings are anagrams.\n");
else
printf("The strings are not anagrams.\n");
return 0;
}